package com.newoffen.com.method;

import com.aventstack.extentreports.ExtentTest;
import com.newoffen.com.listener.ExtentTestNGITestListener;
import com.newoffen.com.page.ShopPageElement;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ShopElementMethod extends ShopPageElement{
    ExtentTestNGITestListener el = new ExtentTestNGITestListener();
    ExtentTest log = el.getlog();
    public void sendUsername(String username){
        log.info("输入用户名");
        input_username.click();
        input_username.clear();
        input_username.sendKeys(username);
    }
    public void sendPasswd(String passwd){
        log.info("输入密码");
        input_passwd.click();
        input_passwd.clear();
        input_passwd.sendKeys(passwd);
    }
    public void sendCode(String code){
        log.info("输入验证码");
        input_code.click();
        input_code.clear();
        input_code.sendKeys(code);
    }
    public void clickBtnOK(){
        log.info("点击确定按钮");
        btn_login.click();
    }
    public void clickMenu_goods(){
        log.info("点击商品菜单");
        menu_goods.click();
    }
    public void clickGoodsList(){
        log.info("点击商品列表按钮");
        btn_goodsList.click();
    }
    public void goodsName(String goodsName){
        log.info("输入商品名称");
        input_goodsName.sendKeys(goodsName);
    }
    public void goodsID(String goodsID){
        log.info("输入商品ID");
        input_goodID.sendKeys(goodsID);
    }
    public void supplier(String supplier){
        log.info("输入供应商");
        input_supplier.sendKeys(supplier);
    }
    public void approval(String supplier){
        log.info("输入批准文号");
        input_approval.sendKeys(supplier);
    }
    public void goodsType(String goodsType){
        log.info("输入批准文号");
        input_goodType.sendKeys(goodsType);
    }
    public void clickBtnSearch(){
        log.info("点击搜索按钮");
        btn_goodsSearch.click();
    }
    public void clickOrder(){
        log.info("点击订单菜单");
        menu_order.click();
    }
    public String getOrderValue(){
        log.info("获取自提订单的名称");
        return getElementValue(menu_pickUpOrder);
    }
    public void searchType(String type){
        log.info("选择搜索类型");
        input_searchType.sendKeys(type);
    }
    public void searchDetail(String detail){
        log.info("输入搜索内容");
        input_searchDetail.sendKeys(detail);
    }
    public void payType(String payType){
        log.info("选择支付方式");
        input_payType.sendKeys(payType);
    }
    public void orderSearch(){
        log.info("点击筛选按钮");
        btn_orderSearch.click();
    }
    public String getOrderID(){
        log.info("获取自提订单的名称");
        return getElementValue(pickUpOrderID);
    }

    public void clickLocalOrder(){
        log.info("点击同城配送按钮");
        menu_localOrder.click();
    }
    public void searchTypeL(String type){
        log.info("选择搜索类型");
        input_searchTypeL.sendKeys(type);
    }
    public void searchDetailL(String detail){
        log.info("输入搜索内容");
        input_searchDetailL.sendKeys(detail);
    }
    public void payTypeL(String payType){
        log.info("选择支付方式");
        input_payTypeL.sendKeys(payType);
    }
    public void orderSearchL(){
        log.info("点击筛选按钮");
        btn_orderSearchL.click();
    }
    public String getOrderIDL(){
        log.info("获取自提订单的名称");
        return getElementValue(LocalOrderID);
    }
    public void clickAudit(){
        log.info("点击处方审核菜单");
        prescriptionAudit.click();
    }
    public void searchID(String type){
        log.info("输入处方审核ID");
        input_orderID.sendKeys(type);
    }
    public void orderSearchA(){
        log.info("点击筛选按钮");
        btn_search.click();
    }
    public void clickAfterSale(){
        log.info("点击售后维权菜单");
        menu_afterSale.click();
    }
    public void saleID(String id){
        log.info("输入处方审核ID");
        input_afterSaleID.sendKeys(id);
    }
    public void saleSearchA(){
        log.info("点击筛选按钮");
        btn_afterSale.click();
    }
    public void clickWithdraw(){
        log.info("点击提现菜单");
        menu_withdraw.click();
    }
    public String getMenuName(){
        log.info("获取提现管理菜单的名称");
        return getElementValue(menu_manage);
    }
    public void clickSettle(){
        log.info("点击结算菜单");
        menu_settle.click();
    }
    public String getEntry(){
        log.info("获取入账菜单的名称");
        return getElementValue(menu_entry);
    }






    public void waitElement(WebDriver driver, WebElement webelement) throws Exception {
//        try{
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.elementToBeClickable(webelement));
//        }catch (Exception e){
//            log.info("报错信息！元素："+webelement+" 没有找到");
//            e.printStackTrace();
//        }
    }
    //    通用判断元素是否存在
    public boolean doesWebElementExist(WebElement webElement) {
        try {
            return webElement.isDisplayed();
        } catch (NoSuchElementException e) {
            return false;
        }
    }
    //滑动鼠标到指定元素
    public void moveToElement(WebDriver driver,WebElement webElement){
        log.info("移动鼠标到元素"+webElement);
        Actions action=new Actions(driver);
        action.moveToElement(webElement).perform();
    }
    public String getElementValue(WebElement webElement){
        log.info("获取元素值"+webElement);
        return webElement.getText();
    }
}
